﻿using Ebusiness_UserService.Model;
using Microsoft.EntityFrameworkCore;
using Volo.Abp.Data;
using Volo.Abp.EntityFrameworkCore;

namespace Ebusiness_UserService.Data;

[ConnectionStringName("UserService")]
public class Ebusiness_UserServiceDbContext : AbpDbContext<Ebusiness_UserServiceDbContext>
{

    //public ILoggerFactory LoggerFactory { get; set; }

    /// <summary>
    /// 程序包管理控制台运行 Code-First
    ///    生成迁移
    ///    Add-migration   生成迁移脚本
    ///    Update-Database   开始迁移
    ///    
    ///    脚本 sql
    ///    Remove-migration    删除脚本
    ///    Script-migration  生成脚本
    ///    Script-migration  xxx   xxx 指定版本区间   Script-migration  project1   project2
    ///    Script-migration  xxx  从哪个版本开始生成脚本
    ///    
    /// 程序包管理控制台运行 DB-First
    ///     Scaffold-DbContext '数据库连接字符串'  EntityFrameworkCore.EntityFrameworkCore.Sqlserver
    /// </summary>
    /// <param name="options"></param>
    public Ebusiness_UserServiceDbContext(DbContextOptions<Ebusiness_UserServiceDbContext> options)
        : base(options)
    {
        
    }

    public DbSet<User> users { get; set; }

     public DbSet<UserLoginHistory> userLoginHistories { get; set; }

    ///// <summary>
    ///// 数据库连接
    ///// </summary>
    ///// <param name="optionsBuilder"></param>
    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        base.OnConfiguring(optionsBuilder);
        //optionsBuilder.UseLoggerFactory(LoggerFactory);  //日志系统
        //optionsBuilder.LogTo(msg => Console.WriteLine(msg)); //日志系统
    }



    protected override void OnModelCreating(ModelBuilder builder)
    {
        base.OnModelCreating(builder);

        /* Include modules to your migration db context */

        /* Configure your own entities here */
        //从当前的程序集加载所有的实体配置
        builder.ApplyConfigurationsFromAssembly(this.GetType().Assembly);
    }
}
